#include <malloc.h>
#include <stdio.h>

void *getMin(void *a, void *b) {
    return a <= b ? a : b;
}

long long minCost(int *nums, int numsSize, int x) {

    int *min = (int *) calloc(1, numsSize * sizeof(int));

    long long result = 0;
    for (int i = 0; i < numsSize; ++i) {
        result += min[i] = nums[i];
    }

    for (int i = 1; i < numsSize; ++i) {
        long long temp = 1ll * i * x;
        for (int j = 0; j < numsSize; ++j) {
            temp += min[j] =  (long long)getMin(&min[j], &nums[(i + j) % numsSize]);
        }
        result = (long long)getMin(&result, &temp);
    }

    return result;

}
int main()
{
    int nums[3] = {20,1,15}, x = 5;
    long long ret = minCost(nums, 3, x);
    printf("%lld", ret);
}